package vincent.com.layouttest;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;

import vincent.com.layouttest.view.CircleColorView;
import vincent.com.layouttest.view.CircleImage;

/**
 * Created by chenzhengwen on 2015/5/13.
 */
public class CircleImageActivity extends ActionBarActivity {
    private CircleColorView colorCircle;
    private CircleImage circleImg;
    private int offset = 0;
    private int time = 5;

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:
                circleImg.setLeftOffset(offset++);
                mHandler.sendEmptyMessageDelayed(1, time);
                break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_circle_img);
        initActionBar();

        colorCircle = (CircleColorView)findViewById(R.id.color_circle);
//        colorCircle.setRadius(40);
        colorCircle.setCircleColor(getResources().getColor(android.R.color.holo_blue_light));

        circleImg = (CircleImage)findViewById(R.id.circle_img);
//        circleImg.setLeftOffsetCustom(true);
        mHandler.sendEmptyMessage(1);
    }

    protected void initActionBar(){
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

  /*  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }*/
}
